***Note: replicators should set directory to open data 
*cd ""

use Pisa.dta, clear

 ****** FIGURE 7*********
  
  
global control_i "Pisa Female Edu_mum  WEALTH  Contact_social Contact_area  i.CNTRYID"
global control_s "Urban Single_sex Size  Private i.Education i.ISCEDO"


quietly:  mixed D  Cog  Contact_school Inclusion  $control_i $control_s  || CNTSCHID: Cog Contact_school   if EU==1, mle nostderr
est store D_EU
estadd local CountryFE "Yes"
estadd local Individual controls "Yes"
estadd local  School controls "Yes"
local N_EU=  e(N)
su D if e(sample), mean
loc Mean_EU:di%8.2fc r(mean)

quietly:  mixed D  Cog  Contact_school Inclusion  $control_i $control_s  || CNTSCHID: Cog  Contact_school    , mle nostderr
est store D_oecd
estadd local CountryFE "Yes"
estadd local Individual controls "Yes"
estadd local  School controls "Yes"
local N_oecd=  e(N)
su D if e(sample), mean
loc Mean_oecd:di%8.2fc r(mean)


  grstyle init
 	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
	grstyle set color      "0 0 0"    "200 200 200" 
    grstyle set graphsize 16cm 13cm 
coefplot (D_EU, label( "ESS sample" "{it:N}=`N_EU'")) (D_oecd, label( "All" "{it:N}=`N_oecd'")) , keep(  Cog Contact_school Inclusion)  xline(0,  lpattern(dash)  )   msymbol(d)  levels(95) ciopts(recast(. rcap))   coeflabels( Cog= """"   Contact_school= `""Intergroup" "contact"'  Inclusion= `""Liberal" "instruction"' , labsize(vsmall) notick labgap(3))   xtitle("Anti-immigration attitudes", size(medsmall)) ylabel(,angle(vertical) labsize(small)) yline(2.5,  lpattern(dot) ) xscale(r(-.2 .2)) xlabel(-.2(.1).2) legend(position(12) rows(1) nobox span )  note("Individual-level controls include gender, maternal and paternal education, country fixed effects." "School-level controls include student staff-ratio, urbanity status, financial/staffing issues, type of school" "(general or vocational) and grade, private or public status." "Outcome means: ESS`Mean_EU' |  All `Mean_oecd'." , size(vsmall) span)  title("{bf:Discriminatory attitudes}")   
  graph save "Figure7a", replace  
  
  
  
quietly:  mixed PD  Cog Contact_school Inclusion $control_i $control_s  || CNTSCHID: Cog Contact_school    if EU==1, mle nostderr 
est store PD_EU
local N_EU=  e(N)
su PD if e(sample), mean
loc Mean_EU:di%8.2fc r(mean)

quietly:  mixed PD Cog Contact_school Inclusion  $control_i $control_s  || CNTSCHID: Cog  Contact_school    , mle nostderr
est store PD_oecd
local N_oecd=  e(N)
su PD if e(sample), mean
loc Mean_oecd:di%8.2fc r(mean)

 
coefplot (PD_EU, label( "ESS sample" "{it:N}=`N_EU'")) (PD_oecd, label( "All" "{it:N}=`N_oecd'")) , keep(Cog Contact_school   Inclusion)  xline(0,  lpattern(dash)  )   msymbol(d)  levels(95) ciopts(recast(. rcap))   coeflabels( Cog= ""   Contact_school= "" Inclusion= "" , labsize(vsmall) notick labgap(3)) ytitle("")  xtitle("Discriminatory climate at school", size(medsmall)) ylabel(,angle(vertical) labsize(small)) yline(2.5,  lpattern(dot) ) xscale(r(-.2 .2)) xlabel(-.2(.1).2) legend(position(12) rows(1) nobox span )  note("Individual-level controls include gender, maternal and paternal education, country fixed effects." "School-level controls include student staff-ratio, urbanity status, financial/staffing issues, type of school" "(general or vocational) and grade, private or public status." "Outcome means: ESS`Mean_EU' |  All `Mean_oecd'." , size(vsmall) span) title("{bf:Perceptions of discrimination}")   
  graph save "Figure7b", replace  
  

          		   grstyle init
	 grstyle set graphsize 14cm 24cm
 graph combine  "Figure7a.gph" "Figure7b.gph",  cols(2) row(1) imargin(l=0 r=0 b=0) ycommon
 graph export "Figure7.tif", replace
 erase "Figure7b.gph"
 erase "Figure7a.gph"
